package com.yun.lib.utils;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * 随时退出程序
 */

public class ActivityCollector {
    private final static List<Activity> activities = new ArrayList<>();

    /**
     * 在onCreate中调用
     */
    public static void addAct(Activity activity) {
        activities.add(activity);
    }

    /**
     * 在onDestroy中调用
     */
    public static void removeAct(Activity activity) {
        if (activities.contains(activity)) {
            activities.remove(activity);
        }
    }

    public static void finishAll() {
        for (Activity activity : activities) {
            if (!activity.isFinishing()) {
                activities.remove(activity);
            }
        }
    }
}
